home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10688 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: ix.netcom.com!news
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Converting Strings to Upper Case
  5. Date: Tue, 19 Mar 1996 13:43:03 GMT
  6. Organization: Netcom
  7. Message-ID: <314eb83f.308884702@nntp.ix.netcom.com>
  8. References: <4ifra6$52i@scipio.cyberstore.ca> <4ih7l3$526@thrush.sover.net>  <4ihl4m$4ca@castle.nando.net> <NEWTNews.827184423.14391.breese@PC_Breese.physio-control>
  9. NNTP-Posting-Host: ix-dc8-01.ix.netcom.com
  10. X-NETCOM-Date: Tue Mar 19  7:42:01 AM CST 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. Brian Reese <breese@kahuna> wrote:
  14.  
  15. > Here's my offering:
  16. > #include <stdio.h>  /* for printf()  */
  17. > #include <ctype.h>  /* for toupper() */
  18. > char * strtoupper( char * );  /* converts string to upper case */
  19. > int main( void )
  20. > {
  21. >     char * test = "my test string";
  22. >     
  23. >     printf( "%s\n", test );
  24. >     printf( "%s\n", strtoupper( test ) );
  25. >     
  26. >     return 0;
  27. > }
  28. > char * strtoupper( char * ptr )  /* converts string to upper case */
  29. > {
  30. >     char * save_ptr = ptr;   /* save pointer for return */
  31. >     
  32. >     while ( *ptr = toupper( *ptr++ ) )
  33. >         ;
  34. >     return save_ptr;
  35. > }
  36.  
  37. Not a very good offering.  There are two obvious problems in your
  38. example.
  39.  
  40. First, the identifier strtoupper with external linkage is reserved.
  41. Defining your own function with external linkage with this name
  42. results in undefined behavior.
  43.  
  44. Second, the expression
  45.  
  46.     *ptr = toupper( *ptr++ )
  47.  
  48. modifies ptr and also acesses its value other than to determine the
  49. new value without an intervening sequence point.  This too results in
  50. undefined behavior.
  51.  
  52. Michael M Rubenstein
  53.